package com.linzelin.filter;

import javax.servlet.*;
import java.io.IOException;

/**
 * 用来解决中文乱码问题的过滤器
 */
public class EncodingFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        //使用过滤器设置下编码格式然后放行
        chain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
}
